

package org.hackday.evetteam;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Point;
import android.os.Bundle;
import android.view.MotionEvent;
import android.widget.ImageView;


public class MapAnnotateActivity extends Activity {

    /**
     * Handle the onCreate event
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(new FingerPrintsView(this));
    }  
    
    
    private static class FingerPrintsView extends ImageView {
        private Paint mPaint ;
        //mPaint = new Paint();
        
        private Bitmap mBmFlowers;
        private Bitmap mBmFingerprint;
        private List<Point> mFingerprintPositions = new ArrayList<Point>();

        private Path path;
        private ArrayList<Path> _graphics = new ArrayList<Path>();
        /**
         * Create the FingerprintsView
         * @param context Context to use
         */
        public FingerPrintsView(Context context) {
            super(context);

            mPaint = new Paint();
            mPaint.setDither(true);
            mPaint.setColor(0xFFFFFF00);
            mPaint.setStyle(Paint.Style.STROKE);
            mPaint.setStrokeJoin(Paint.Join.ROUND);
            mPaint.setStrokeCap(Paint.Cap.ROUND);
            mPaint.setStrokeWidth(3);
            // Create the bitmaps
            mBmFlowers = BitmapFactory.decodeResource(getResources(),R.drawable.screen);
            mBmFingerprint = BitmapFactory.decodeResource(getResources(),
            	R.drawable.red);
        }

        /**
         * Draw the prints over the  field
         */
        @Override
        protected void onDraw(Canvas canvas) {
            canvas.drawBitmap(mBmFlowers, 0, 0, mPaint);

            // Draw each finger print
            for (Point position: mFingerprintPositions) {
                canvas.drawBitmap(
                    mBmFingerprint, position.x, position.y, mPaint);
            }
            
           /* for (Path path : _graphics) {
				//canvas.drawPoint(graphic.x, graphic.y, mPaint);
            	//path.
				canvas.drawPath(path, mPaint);
				//canvas.
			}*/
        }

        /**
         * Add a new finger print to the list on a finger press event
         */
        @Override
        public boolean onTouchEvent(MotionEvent event) {
            switch (event.getAction()) {
                case MotionEvent.ACTION_DOWN:

                    // Adjust so the centre appears where the touch occurred
                    Point position = new Point(
                        (int) event.getX() - mBmFingerprint.getWidth() / 2,
                        (int) event.getY() - mBmFingerprint.getHeight() / 2
                    );

                    
                    // Store the coordinates of the touch in the finger print List
                    mFingerprintPositions.add(position);

                    // Update the display
                    invalidate();
                    break;
                    
                case MotionEvent.ACTION_MOVE: {

                    int X = (int) event.getX();
                    int Y = (int) event.getY();
                    Point position1 = new Point(
                            (int) event.getX() - mBmFingerprint.getWidth() / 2,
                            (int) event.getY() - mBmFingerprint.getHeight() / 2
                        );

                        
                        // Store the coordinates of the touch in the finger print List
                        mFingerprintPositions.add(position1);

                        // Update the display
                        invalidate();
                    break;

            }  
            }
            return true;
        }
        
      /*  public boolean onTouchEvent(MotionEvent event) {
            //synchronized (_thread.getSurfaceHolder()) {
            	if(event.getAction() == MotionEvent.ACTION_DOWN){
            		path = new Path();
            		path.moveTo(event.getX(), event.getY());
            		path.lineTo(event.getX(), event.getY());
            	}else if(event.getAction() == MotionEvent.ACTION_MOVE){
            		path.lineTo(event.getX(), event.getY());
            	}else if(event.getAction() == MotionEvent.ACTION_UP){
            		path.lineTo(event.getX(), event.getY());
            		_graphics.add(path);
            	}
            	
            	return true;
            //}
		}*/
		
    }
}